package com.xf.service.producer;

import com.xf.common.core.authe.feign.UserConsumer;
import com.xf.common.core.domain.DmpResult;
import com.xf.common.core.entity.dmp.DmpAuthResourceRole;
import com.xf.common.core.entity.dmp.DmpAuthUser;
import com.xf.common.core.entity.dmp.RegisterUserDto;
import com.xf.common.core.entity.system.SystemUser;
import com.xf.service.DmpAuthResourceService;
import com.xf.service.DmpAuthUserService;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author JoeyLiu
 * @create 2022-03-31 16:23
 */
@RestController
public class UserConsumerImpl implements UserConsumer {
    @Resource
    private DmpAuthUserService dmpAuthUserService;
    @Resource
    private DmpAuthResourceService resourceService;

    @Override
    public DmpResult<DmpAuthUser> selectByUserCode(String userCode) {
        return dmpAuthUserService.selectByUserCode(userCode);
    }

    @Override
    public DmpResult updataUser(DmpAuthUser user) {
        dmpAuthUserService.updatePassword(user.getPassword());
        return DmpResult.success();
    }

    @Override
    public DmpResult<DmpAuthUser> selectByNameOrEmail(String user) {
        return dmpAuthUserService.selectByNameOrEmail(user);
    }

    @Override
    public DmpResult<SystemUser> findByName(String username) {
        return DmpResult.data(dmpAuthUserService.findByName(username));
    }

    /**
     * 查询openId
     *
     * @param openId
     * @return
     */
    @Override
    public DmpResult<SystemUser> findByOpenId(String openId) {
        return dmpAuthUserService.findByOpenId(openId);

    }

    @Override
    public DmpResult<SystemUser> findByMobile(String mobile) {
        return dmpAuthUserService.findByMobile(mobile);
    }

    @Override
    public DmpResult<SystemUser> registUser(RegisterUserDto registerUserDto) {
        return dmpAuthUserService.registUser(registerUserDto);
    }

    @Override
    public DmpResult<List<DmpAuthResourceRole>> getAllResourceRole() {
        return DmpResult.data(resourceService.getAllResourceRole());
    }

}
